package com.lwlk.util.reflact;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.lwlk.util.rubbish.havefun.WTF.P;

public class Reflact {

    public static List<TypeNode> asTypeNodeList(Object ... objs) {
        return Stream.of(objs).map(TypeNode::new).collect(Collectors.toList());
    }

    private static class TypeNode {

        Object object;

        TypeNode(Object object) {
            this.object = object;
        }

        public <T> T recover() throws ClassNotFoundException {
            return (T) Class.forName(object.getClass().getName()).cast(object);
        }
    }

    public static void main(String[] args) {

        List<TypeNode> list = Reflact.asTypeNodeList("123", 5, 1.5);

        try {
            String v1 = list.get(0).recover();
            int v2 = list.get(1).recover();
            double v3 = list.get(2).recover();
            P(v1, v2, v3);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
